package com.xoa.service.hr.staffCare;

import com.xoa.dao.common.HrCodeMapper;
import com.xoa.dao.hr.staffCare.HrStaffCareMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.common.HrCode;
import com.xoa.model.common.HrCodeExample;
import com.xoa.model.enclosure.Attachment;
import com.xoa.model.hr.HrTransferWithBLOBs;
import com.xoa.model.hr.HrphotoWithBLOBs;
import com.xoa.model.hr.staffCare.HrStaffCare;
import com.xoa.model.hr.staffCare.HrStaffCareWithBLOBs;
import com.xoa.model.users.Users;
import com.xoa.util.*;
import com.xoa.util.common.StringUtils;
import com.xoa.util.common.log.FileUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.common.wrapper.BaseWrapper;
import com.xoa.util.page.PageParams;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author 左春晖      员工关怀service
 * @date 2018/7/20 14:02
 * @desc
 */
@Service
public class HrStaffCareService {

    @Resource
    HrStaffCareMapper hrStaffCareMapper;

    @Resource
    UsersMapper usersMapper;

    @Resource
    HrCodeMapper hrCodeMapper;

    /**
     * 添加
     */
    public ToJson addHrStaffCare(HttpServletRequest request, HrStaffCareWithBLOBs hrStaffCareWithBLOBs){
        ToJson json = new ToJson();
        Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionId);
        //创建者用户名
        hrStaffCareWithBLOBs.setCreateUserId(user.getUserId());
        //创建者部门编号
        hrStaffCareWithBLOBs.setCreateDeptId(user.getDeptId());
//        Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
        Users users = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionId);
            hrStaffCareWithBLOBs.setCreateUserId(users.getUserName());
            hrStaffCareWithBLOBs.setCreateDeptId(users.getDeptId());
            hrStaffCareWithBLOBs.setAddTime(new Date());
            hrStaffCareWithBLOBs.setLastUpdateTime(new Date());
            if (!StringUtils.checkNull(hrStaffCareWithBLOBs.getCareDates())){
                hrStaffCareWithBLOBs.setCareDate(DateFormat.getDates(hrStaffCareWithBLOBs.getCareDates()));
            }
//        if (hrStaffCareWithBLOBs.getByCareStaffs().contains(",")) {
//            String substring = hrStaffCareWithBLOBs.getByCareStaffs().substring(0, hrStaffCareWithBLOBs.getByCareStaffs().length() - 1);
//            hrStaffCareWithBLOBs.setByCareStaffs(substring);
//        }
        int temp = hrStaffCareMapper.insertSelective(hrStaffCareWithBLOBs);
           if(temp>0){
            json.setFlag(0);
            json.setMsg("ok");
           }else {
               json.setFlag(1);
               json.setMsg("添加失败");
           }
        return json;
    }

    /**
     * 修改
     */
    public ToJson upHrStaffCare(HttpServletRequest request,HrStaffCareWithBLOBs hrStaffCareWithBLOBs){
        ToJson json = new ToJson();
        hrStaffCareWithBLOBs.setLastUpdateTime(new Date());
        int temp = hrStaffCareMapper.updateByPrimaryKeySelective(hrStaffCareWithBLOBs);
        if (temp>0){
            json.setFlag(0);
            json.setMsg("OK");
        }else {
            json.setFlag(1);
            json.setMsg("修改失败");
        }
        return json;
    }

    /**
     * 删除
     */
    public ToJson deleteHrStaffCare(String[] careId){
        ToJson json = new ToJson();
        int temp = hrStaffCareMapper.deleteByPrimaryKeyID(careId);
        if (temp > 0) {
            json.setFlag(0);
            json.setMsg("success");
        } else {
            json.setFlag(1);
            json.setMsg("false");
        }
        return json;
    }

    /**
     * 查询
     */
    public ToJson selectHrStaffCare(HttpServletResponse response, HttpServletRequest request, HrStaffCareWithBLOBs hrStaffCareWithBLOBs, Integer page, Integer pageSize, boolean useFlag, String export) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
        ToJson json = new ToJson<>();
        List<HrStaffCareWithBLOBs> list = new ArrayList<HrStaffCareWithBLOBs>();
        Map<String,Object> map= new HashMap<>();
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(useFlag);
        map.put("page", pageParams);
        if(hrStaffCareWithBLOBs.getCareId()!=null){
            map.put("careId",hrStaffCareWithBLOBs.getCareId());
        }
        if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getCareType())){
            map.put("careType",hrStaffCareWithBLOBs.getCareType());
        }
        if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getCareDateSta())){
            map.put("careDateSta",hrStaffCareWithBLOBs.getCareDateSta());
        }
        if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getCareDateEnd())){
            map.put("careDateEnd",hrStaffCareWithBLOBs.getCareDateEnd());
        }
        if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getCareFeesSta())){
            map.put("careFeesSta",Integer.valueOf(hrStaffCareWithBLOBs.getCareFeesSta()));
        }
        if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getCareFeesEnd())){
            map.put("careFeesEnd",Integer.valueOf(hrStaffCareWithBLOBs.getCareFeesEnd()));
        }
        if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getCareContent())){
            map.put("careContent",hrStaffCareWithBLOBs.getCareContent());
        }
        if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getParticipants())){
            map.put("participants",hrStaffCareWithBLOBs.getParticipants());
        }
        //被关怀人员
        if (hrStaffCareWithBLOBs.getByCareStaffs()!=null && hrStaffCareWithBLOBs.getByCareStaffs()!=""){
            //判断用户是否为空并转化字符串
            if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getByCareStaffs().toString())){
                String fromIds = hrStaffCareWithBLOBs.getByCareStaffs().toString();
                String[] substring = fromIds.split(",");//分割
                List byCareStaffs=new ArrayList();
                for(String s:substring){
                    byCareStaffs.add(s+",");
                }
                map.put("byCareStaffs",byCareStaffs);
            }
        }
        //参与人
//        if (hrStaffCareWithBLOBs.getParticipants()!=null && hrStaffCareWithBLOBs.getParticipants()!=""){
//            //判断用户是否为空并转化字符串
//            if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getParticipants().toString())){
//                String fromIds = hrStaffCareWithBLOBs.getParticipants().toString();
//                String[] substring = fromIds.split(",");//分割
//                List participants=new ArrayList();
//                for(String s:substring){
//                    participants.add(s+",");
//                }
//                map.put("participants",participants);
//            }
//        }
        list = hrStaffCareMapper.Allselect(map);
        //处理被参与人返回被参与人的姓名
        for (HrStaffCareWithBLOBs  hr :list){
            if (hr.getByCareStaffs().contains(",")){
                String substring = hr.getByCareStaffs().substring(0, hr.getByCareStaffs().length() - 1);
                String username = usersMapper.getUsernameByUserId(substring);
                hr.setByCareStaffs(username);
            }
            if (hr.getCareType().equals("1")){
                hr.setCareType("节日关怀");
            }else if(hr.getCareType().equals("2")){
                hr.setCareType("生日关怀");
            }

            //处理参与人  返回参与人姓名
           if(!StringUtils.checkNull(hr.getParticipants())){
                String[] str = hr.getParticipants().split(",");
                String username ="";
                String usernames = "";
                for(String  hr2 : str){
                 username = usersMapper.getUsernameByUserId(hr2);
                    usernames += username+",";
                }
                if (username!=null){
                    hr.setParticipants(usernames);
                }
            }
            //处理类型  用于返显
            if (hr.getCareType()!=null){
                switch(hr.getCareType()){
                    case "1":
                        hr.setCareType("节日关怀");
                        break;
                    case "2":
                        hr.setCareType("生日关怀");
                        break;
                }
            }
            // 附件处理
            List<Attachment> attachmentList=new ArrayList<Attachment>();
            if(hr.getAttachmentName()!=null&&!"".equals(hr.getAttachmentName())){
                attachmentList= GetAttachmentListUtil.returnAttachment(hr.getAttachmentName(),hr.getAttachmentId(),"xoa" + (String) request.getSession().getAttribute("loginDateSouse"), GetAttachmentListUtil.INCENTIVE);
            }
            hr.setAttachmentList(attachmentList);
            //处理日期
            hr.setCareDates(DateFormat.getDatestr(hr.getCareDate()));

        }
        if("1".equals(export)){
            HSSFWorkbook workbook1 = ExcelUtil.makeExcelHead("员工关怀信息", 7);
            String[] secondTitles = {"被关怀员工", "关怀类型","关怀开支费用","关怀日期","参与人","关怀内容","关怀效果"};
            HSSFWorkbook workbook2 = ExcelUtil.makeSecondHead(workbook1, secondTitles);
            String[] beanProperty = {"byCareStaffs","careType","careFees","careDates","participants","careContent","careEffects"};
            HSSFWorkbook workbook = ExcelUtil.exportExcelData(workbook2, list, beanProperty);
            OutputStream out = response.getOutputStream();
            String filename = "员工关怀信息.xls";
            filename = FileUtils.encodeDownloadFilename(filename, request.getHeader("user-agent"));
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("content-disposition", "attachment;filename=" + filename);
            workbook.write(out);
            out.close();
        }
        json.setMsg("OK");
        json.setFlag(0);
        json.setTurn(true);
        json.setObj(list);
        json.setTotleNum(pageParams.getTotal());
        return json;
    }

    /**
     * 根据ID查询
     */
    public ToJson selectHrStaffCareId(HttpServletRequest request,Integer careId){
        ToJson json = new ToJson(1,"err");
        Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
        Users user = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionId);
        try{
            //根据ID查找下对应的用户
            HrStaffCareWithBLOBs hrStaffCareWithBLOBs =  hrStaffCareMapper.selectByPrimaryKey(careId);
            String name="";
            if(hrStaffCareWithBLOBs !=null){
               if(hrStaffCareWithBLOBs.getByCareStaffs()!=null){
                    String ids[]= hrStaffCareWithBLOBs.getByCareStaffs().split(",");
                   String names ="";
                    for(String id:ids){
                        name= usersMapper.getUsernameByUserId(id);
                        names+=name+",";
                    }
                   if (name!=null){
                       hrStaffCareWithBLOBs.setByCareStaffss(names);
                   }else{
                       hrStaffCareWithBLOBs.setByCareStaffss(hrStaffCareWithBLOBs.getByCareStaffs());
                   }
                }

                //處理參與人
                if(!StringUtils.checkNull(hrStaffCareWithBLOBs.getParticipants())){
                    String[] str = hrStaffCareWithBLOBs.getParticipants().split(",");
                    String username ="";
                    String usernames = "";
                    for(String  hr2 : str){
                        username = usersMapper.getUsernameByUserId(hr2);
                        usernames += username+",";
                    }
                    if (username!=null){
                        hrStaffCareWithBLOBs.setParticipantss(usernames);
                    }else {
                        hrStaffCareWithBLOBs.setParticipantss(hrStaffCareWithBLOBs.getParticipants());
                    }
                }
                if (hrStaffCareWithBLOBs.getCareType().equals("1")){
                    hrStaffCareWithBLOBs.setCareType("节日关怀");
                }else if (hrStaffCareWithBLOBs.getCareType().equals("1")){
                    hrStaffCareWithBLOBs.setCareType("生日关怀");
                }
                //附件处理
                List<Attachment> attachmentList=GetAttachmentListUtil.returnAttachment(hrStaffCareWithBLOBs.getAttachmentName(),hrStaffCareWithBLOBs.getAttachmentId(),"xoa" + (String) request.getSession().getAttribute("loginDateSouse"), GetAttachmentListUtil.WORKEXPERIENCE);
                hrStaffCareWithBLOBs.setAttachmentList(attachmentList);
                json.setObject(hrStaffCareWithBLOBs);
                json.setFlag(0);
                json.setMsg("详情查询成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return json;
    }

    /**
     * @author 程叶同
     * @date 2018/7/23 16:33
     * @desc  人力资源系统代码表
     */
    private static final String HR_SCHOOL="HR_STAFF_CARE";
    public BaseWrapper getHrCodes(String type){
        BaseWrapper baseWrapper=new BaseWrapper();
        List<HrCode> hrCodes=new ArrayList<>();
        HrCodeExample hrCodeExample=new HrCodeExample();
        HrCodeExample.Criteria criteria = hrCodeExample.createCriteria();
        hrCodeExample.setOrderByClause("cast(CODE_NO as SIGNED INTEGER) ASC");
        if ("edu".equals(type)) { //获取状态
            criteria.andParentNoEqualTo(HR_SCHOOL);
            hrCodes = hrCodeMapper.selectByExampleWithBLOBs(hrCodeExample);
        }
//        } else if ("degree".equals(type)) {//获取证照类型
//            criteria.andParentNoEqualTo(HR_DEGREE);
//            hrCodes=hrCodeMapper.selectByExampleWithBLOBs(hrCodeExample);
//        }
        baseWrapper.setMsg("ok");
        baseWrapper.setFlag(true);
        baseWrapper.setData(hrCodes);
        baseWrapper.setStatus(true);
        return  baseWrapper;
    }
    /**
     * 导入
     */
    public ToJson imports(HttpServletRequest request, HttpServletResponse response, MultipartFile file) {
        ToJson json = new ToJson(1,"error");
        try {
            //判读当前系统
            //读取配置文件
            ResourceBundle rb = ResourceBundle.getBundle("upload");
            String osName = System.getProperty("os.name");
            StringBuffer path = new StringBuffer();
                 StringBuffer buffer=new StringBuffer();
        if(osName.toLowerCase().startsWith("win")){
            //sb=sb.append(rb.getString("upload.win"));
            //判断路径是否是相对路径，如果是的话，加上运行的路径
            String uploadPath = rb.getString("upload.win");
            if(uploadPath.indexOf(":")==-1){
                //获取运行时的路径
                String basePath = this.getClass().getClassLoader().getResource(".").getPath()+ File.pathSeparator;
                //获取截取后的路径
                String str2 = "";
                if(basePath.indexOf("/xoa")!=-1){
                    //获取字符串的长度
                    int length = basePath.length();
                    //返回指定字符在此字符串中第一次出现处的索引
                    int index = basePath.indexOf("/xoa");
                    //从指定位置开始到指定位置结束截取字符串
                    str2=basePath.substring(0,index);
                }
                path = path.append(str2 + "/xoa");
            }
            path.append(uploadPath);
            buffer=buffer.append(rb.getString("upload.win"));
        }else{
            path=path.append(rb.getString("upload.linux"));
            buffer=buffer.append(rb.getString("upload.linux"));
        }
            int success=0;
            // 判断是否为空文件
            if (file.isEmpty()) {
                json.setMsg("请上传文件！");
                json.setFlag(1);
                return json;
            } else {
                String fileName = file.getOriginalFilename();
                if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) {
                    String uuid = UUID.randomUUID().toString().replaceAll("-", "");
                    int pos = fileName.indexOf(".");
                    String extName = fileName.substring(pos);
                    String newFileName = uuid + extName;
                    File dest = new File(path.toString(), newFileName);
                    file.transferTo(dest);
                    // 将文件上传成功后进行读取文件
                    // 进行读取的路径
                    String readPath = path.append(System.getProperty("file.separator")).append(newFileName).toString();
                    InputStream in = new FileInputStream(readPath);
                    HSSFWorkbook excelObj = new HSSFWorkbook(in);
                    HSSFSheet sheetObj = excelObj.getSheetAt(0);
                    Row row = sheetObj.getRow(0);
                    int colNum = row.getPhysicalNumberOfCells();
                    int lastRowNum = sheetObj.getLastRowNum();
                    HrStaffCareWithBLOBs hrStaffCareWithBLOBs = null;
                    for (int i = 1; i <= lastRowNum; i++) {
                        hrStaffCareWithBLOBs = new HrStaffCareWithBLOBs();
                        row = sheetObj.getRow(i);
                        String value = "";
                        if (row != null) {
                            for (int j = 0; j < colNum; j++) {
                                Cell cell = row.getCell(j);
                                if (cell != null) {
                                    switch (j) {
                                        case 0:
                                            // 关怀类型
                                            if(row.getCell(0)!=null){
                                                row.getCell(0).setCellType(CellType.STRING);
                                                hrStaffCareWithBLOBs.setCareType(row.getCell(0).getStringCellValue());
                                            }
//                                            if (cell.getStringCellValue()!=null) {
//                                                hrStaffCareWithBLOBs.setCareType(cell.getStringCellValue());
//                                            }
//                                            Users users = usersMapper.getUserByUserName(cell.getStringCellValue());
////                                            Department department = departmentMapper.getDeptById(users.getDeptId());
//                                            hrStaffCareWithBLOBs.setCreateUserId(cell.getStringCellValue());
////                                            hrphotoWithBLOBs.setCreateDeptId(department.getDeptId());
                                            break;
                                        case 1:
                                            // 关怀费用开支
                                            if(row.getCell(1)!=null){
                                                row.getCell(1).setCellType(CellType.STRING);
                                                hrStaffCareWithBLOBs.setCareFees(row.getCell(1).getStringCellValue());
                                            }
//                                            if (cell.getStringCellValue() != null) {
////                                                Users user = usersMapper.getUserByUserName(cell.getStringCellValue());
//                                                hrStaffCareWithBLOBs.setCareFees(cell.getStringCellValue());
//                                            }
                                            break;
                                        case 2:
                                            //被关怀员工用户名
                                            if (cell.getStringCellValue()!=null) {
                                                hrStaffCareWithBLOBs.setByCareStaffss(cell.getStringCellValue());
                                            }break;
                                        case 3:
                                            //被关怀员工
                                            if(cell.getStringCellValue()!=null){
                                                hrStaffCareWithBLOBs.setByCareStaffs(cell.getStringCellValue());
                                            }
                                            break;
                                        case 4:
                                            //关怀日期
                                            if (cell.getCellType() == CellType.NUMERIC) {
                                                short format = cell.getCellStyle().getDataFormat();
                                                SimpleDateFormat sdf = null;
                                                if (format == 14 || format == 31 || format == 57 || format == 58) {
                                                    //日期
                                                    sdf = new SimpleDateFormat("yyyy-MM-dd");
                                                }
                                                double v = cell.getNumericCellValue();
                                                Date date = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(v);
                                                hrStaffCareWithBLOBs.setCareDate(date);
                                                break;
                                            }
                                            hrStaffCareWithBLOBs.setCareDate(cell.getDateCellValue());
                                            break;
                                        case 5:
                                            // 关怀效果
                                           if (!StringUtils.checkNull(cell.getStringCellValue())) {
                                               hrStaffCareWithBLOBs.setCareEffects(cell.getStringCellValue());
                                           }
                                           break;
                                        case 6:
                                            // 参与人
                                            if (cell.getStringCellValue() !=null) {
                                                hrStaffCareWithBLOBs.setParticipants(cell.getStringCellValue());
                                                break;
                                            }
                                            hrStaffCareWithBLOBs.setParticipants(cell.getStringCellValue());
                                            break;
                                        case 7:
                                            // 关怀内容
                                            if (cell.getStringCellValue()!=null) {
                                                hrStaffCareWithBLOBs.setCareContent(cell.getStringCellValue());
                                            }break;
                                    }

                                }
                            }
                            if(hrStaffCareWithBLOBs!=null){
                                hrStaffCareWithBLOBs.setAddTime(new Date());
                                hrStaffCareWithBLOBs.setLastUpdateTime(new Date());
                                Cookie redisSessionId = CookiesUtil.getCookieByName(request,"redisSessionId");
                                Users user = SessionUtils.getSessionInfo(request.getSession(),Users.class,new Users(),redisSessionId);
                                //创建者用户名
                                hrStaffCareWithBLOBs.setCreateUserId(user.getUserId());
                                //创建者部门编号
                                hrStaffCareWithBLOBs.setCreateDeptId(user.getDeptId());
                                int a =hrStaffCareMapper.insertSelective(hrStaffCareWithBLOBs);
                                if (a!=0){
                                    success = success + 1;
                                }
                            }

                        }
                    }
                }
            }
            HrphotoWithBLOBs temp=new HrphotoWithBLOBs();
            temp.setCount(success);
            json.setFlag(0);
            json.setMsg("ok");
            json.setObject(temp);
        } catch (Exception e) {
            e.printStackTrace();
            json.setMsg("数据保存异常");
            json.setFlag(1);
        }
        return json;
    }



    /**
     * 创建者：戚中校
     * 方法作用：根据条件查询数量
     * @param
     * @param deptId(传入的多个部门的编号)
     * @return 返回的json字符串中  nums是返回的结果的数量
     *
     */

    public ToJson<HrStaffCare> selectNumByCon(HrStaffCare record, Integer[] deptId) {
        ToJson toJson = new ToJson();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            if (deptId != null && deptId.length > 0){
                map.put("deptId",deptId);
            }
            map.put("record",record);
            List<HrStaffCare> list = hrStaffCareMapper.selectNumByCon(map);

            for(HrStaffCare hrStaffCare:list){
                if(hrStaffCare.getCareType() != null){
                    HrCode hr_staff_contract1 = hrCodeMapper.selectCode("HR_STAFF_CARE",hrStaffCare.getCareType());
                    if (hr_staff_contract1 != null) {
                        hrStaffCare.setCareTypeName(hr_staff_contract1.getCodeName());
                    } else {
                        hrStaffCare.setCareTypeName("其它");
                    }
                }
            }
            if(list.size() >= 0){
                toJson.setObj(list);
                toJson.setMsg("ok");
                toJson.setFlag(0);
            }else{
                toJson.setMsg("err");
                toJson.setFlag(1);
            }

        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg("err");
            toJson.setFlag(1);
        }
        return toJson;
    }
    public ToJson<HrStaffCareWithBLOBs> getByStaffName(String staffName, Integer page, Integer pageSize, boolean useFlag){
        ToJson<HrStaffCareWithBLOBs> json=new ToJson<HrStaffCareWithBLOBs>();
        //分页
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(useFlag);
        HashMap<String,Object> map = new HashMap();
        map.put("pageParams", pageParams);
        map.put("staffName",staffName);
        try{
            List<HrStaffCareWithBLOBs> list=hrStaffCareMapper.getByStaffName(map);
            if(list.size()>0){
                for(HrStaffCareWithBLOBs care:list){
                    //合同类型
                    HrCode hr_staff_contract2 = hrCodeMapper.selectCode("HR_STAFF_CARE",care.getCareType());
                    if (hr_staff_contract2 != null) {
                        care.setCareTypeName(hr_staff_contract2.getCodeName());
                    } else {
                        care.setCareTypeName(" ");
                    }
                    if(care.getByCareStaffs()!=null){
                        String[] str=care.getByCareStaffs().split(",");
                        StringBuffer name=new StringBuffer();
                        for(int i=0;i<str.length;i++){
                            name.append(usersMapper.getUsernameByUserId(str[i])+",");  //根据 id 找名字
                        }
                        care.setByCareStaffs(name.toString());
                    }
                        if(care.getParticipants()!=null){
                            String[] str2=care.getParticipants().split(",");
                            StringBuffer name=new StringBuffer();
                            for(int i=0;i<str2.length;i++){
                                name.append(usersMapper.getUsernameByUserId(str2[i])+",");  //根据 id 找名字
                            }
                            care.setParticipants(name.toString());
                    }
                }
                json.setObj(list);
            }
            json.setTotleNum(hrStaffCareMapper.getByStaffNameCount(staffName));
            json.setFlag(0);
            json.setMsg("true");
        }catch (Exception e){
            e.printStackTrace();
            json.setFlag(1);
            json.setMsg("err");
        }
        return json;
    }
}
